Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@coral-xyz/anchor
Advanced tools
@coral-xyz/anchor is a framework for Solana's Sealevel runtime providing several developer tools to build, deploy, and interact with smart contracts on the Solana blockchain. It simplifies the process of writing Solana programs by offering a set of Rust macros and a TypeScript client for interacting with these programs.
Smart Contract Development
This code demonstrates how to set up a client to interact with a Solana smart contract using the @coral-xyz/anchor framework. It shows how to load the program's IDL, set up a provider, and call a function on the smart contract.
const anchor = require('@coral-xyz/anchor');
// Define the provider
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
// Load the IDL
const idl = JSON.parse(require('fs').readFileSync('./target/idl/my_program.json', 'utf8'));
// Address of the deployed program
const programId = new anchor.web3.PublicKey('YourProgramPublicKey');
// Generate the program client from IDL
const program = new anchor.Program(idl, programId);
// Interact with the program
async function main() {
// Call a function from the smart contract
await program.rpc.initialize();
}
main().catch(err => console.error(err));
Testing Smart Contracts
This code provides a basic test setup for a Solana smart contract using the @coral-xyz/anchor framework. It uses Mocha for testing and demonstrates how to initialize a program and assert the state of an account.
const anchor = require('@coral-xyz/anchor');
const assert = require('assert');
describe('my-program', () => {
// Configure the client to use the local cluster.
const provider = anchor.AnchorProvider.local();
anchor.setProvider(provider);
const program = anchor.workspace.MyProgram;
it('Initializes the account', async () => {
// Add your test here.
const tx = await program.rpc.initialize();
console.log('Transaction signature', tx);
// Fetch the account and assert its state
const account = await program.account.myAccount.fetch(provider.wallet.publicKey);
assert.ok(account.data.eq(new anchor.BN(0)));
});
});
@solana/web3.js is a JavaScript API for interacting with the Solana blockchain. While it provides lower-level access to Solana's features, it lacks the higher-level abstractions and developer tools that @coral-xyz/anchor offers, such as IDL generation and client-side program interaction.
TypeScript client for Anchor programs.
@coral-xyz/anchor
depends on node.js native modules. Therefore, webpack 5 will not work with current version. You will either need to rollback to webpack 4, or use a polyfill for each missing dependency.[0.28.0] - 2023-06-09
async
feature flag to use an asynchronous anchor-client (#2488).approve_collection_authority
, bubblegum_set_collection_size
, burn_edition_nft
, burn_nft
, revoke_collection_authority
, set_token_standard
, utilize
, unverify_sized_collection_item
, unverify_collection
(#2430)token_program
constraint to Token
, Mint
, and AssociatedToken
accounts in order to override required token_program
fields and use different token interface implementations in the same instruction (#2460)anchor init
and anchor new
take an option --solidity
which creates solidity code rather than rust. anchor build
and anchor test
work accordingly (#2421)idl set-buffer
, idl set-authority
and idl close
take an option --print-only
. which prints transaction in a base64 Borsh compatible format but not sent to the cluster. It's helpful when managing authority under a multisig, e.g., a user can create a proposal for a Custom Instruction
in SPL Governance (#2486).emit_cpi!
and #[event_cpi]
macros(behind event-cpi
feature flag) to store event logs in transaction metadata (#2438).keys sync
command to sync program id declarations (#2505).1.16.0
and specify maximum version of <1.17.0
(#2512).anchor deploy
command's --program-name
argument accepts program lib names (#2519).AccountClient
type to it's appropriate account type (#2440)program_id
, accounts
, ix_data
, remaining_accounts
in instruction arguments (#2464)metadata.address
generation in IDL after deploying with a custom keypair (#2485)anchor new
not updating Anchor.toml
(#2516).FAQs
Anchor client
We found that @coral-xyz/anchor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.